package com.day1020;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 精灵类:玩家机，敌机，子弹，道具机等元素都属于精灵对象
 */
public abstract class FlySprite {
    protected BufferedImage image;
    protected int x;
    protected int y;
    protected int width;
    protected int height;
    protected boolean dead;
    /**
     * 初始化精灵信息
     */
    public abstract void init();
    /**
     * 绘制
     * @param g
     */
    public void draw(Graphics g){
        g.drawImage(image,x,y,width,height,null);
    }
    /**
     * 销毁
     */
    public abstract void destroy();

    //  碰撞类
    public boolean isHit(FlySprite other){
        //  左侧
        if (this.x > other.x && this.x > other.x + other.width){
            return false;
        }
        //  右侧
        if (this.x < other.x && other.x < this.x + this.width){
            return false;
        }
        //  上侧
        if (this.y > other.y && this.y > other.y + other.height){
            return false;
        }
        //  下侧
        if (this.y < other.y && other.y < this.y + this.height){
            return false;
        }
        //  相交碰撞
        return true;
    }

    public boolean isDead() {
        return dead;
    }

    public void setDead(boolean dead) {
        this.dead = dead;
    }
}
